namespace Bootsy.Tests.Jira

import System
import NUnit.Framework
import Bootsy.Tests
import Bootsy.Core
import Bootsy.Jira
import Bootsy.Jira.RPC

[TestFixture]
class JiraBotTestFixture:
	
	_chat as DummyChat
	_jiraBot as JiraBot
	
	[Test]
	def IdsLoad():
		_jiraBot.OnMessage(_chat.NewMessage("!jira ids"))
		
		AssertMessage """
Adriano: 6 IDS
Carl: 3 IDS
Rodrigo: 3 IDS
Total: 6 IDS
"""	

	
	[Test]
	def JiraTicketMessage():
		
		_jiraBot.OnMessage(_chat.NewMessage("!jira COR-123"))
		
		AssertMessage "COR-123 - Open - Issue 123"
		
	def AssertMessage(msg as string):
		Assert.AreEqual(1, len(_chat.Messages))
		Assert.AreEqual(msg.Trim(), _chat.Messages[0].Trim())
		
	def originalEstimateIds(value):
		return RemoteCustomFieldValue(
				customfieldId: "customfield_10040",
				values: (value.ToString(),))
				
	def peers(*values as (string)):
		return RemoteCustomFieldValue(
				customfieldId: "customfield_10000",
				values: values)
	
	def SetUpJiraService():
		return DummyJiraService(
			Issues: (
				RemoteIssue(
					assignee: "Rodrigo",
					key: "COR-123",
					status: "1",
					summary: "Issue 123",
					resolution: "open",
					customFieldValues: (
						originalEstimateIds(3),
						peers("Adriano")
					)
				),
				RemoteIssue(
					assignee: "Adriano",
					key: "COR-124",
					status: "3",
					summary: "Issue 124",
					resolution: "open",
					customFieldValues: (
						originalEstimateIds(3),
						peers("Carl")
					)
				),
			),
			Resolutions: (
				RemoteResolution(
					id: "closed",
					name: "Closed"
				),
				RemoteResolution(
					id: "open",
					name: "Open"
				),
			)
		)

	[SetUp]
	def SetUp():
		_jiraBot = JiraBot(SetUpJiraService())
		_chat = DummyChat()
		
	
